﻿<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" CodeFile="Leaveword.aspx.cs" Inherits="Leaveword" %>
<%@ Register Src="UserControls/Header.ascx" TagName="Header"  TagPrefix="uc"%>
<%@ Register Src="UserControls/Sidebar.ascx" TagName="Sidebar"  TagPrefix="uc"%>
<%@ Register Src="UserControls/Footer.ascx" TagName="Footer"  TagPrefix="uc"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="Generator" content="EditPlus" />
	<meta name="Author" content="FanFuBlog" />
	<meta name="Keywords" content="前端,前端开发,web前端,web前端开发,前端工程师,前端个人博客,前端开发工具,jquery插件,浏览器兼容,子曾经曰过" />
	<meta name="Description" content="子曾经曰过博客,大家给子曾经曰过留言的地方!" />
    <title>给我留言&ndash;WEB前端开发&ndash;专注前端开发，关注用户体验</title>
	<link href="css/base.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.6.1.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div class="wraper">
	<uc:Header ID="Header1" runat="server" />
	<div id="container" class="clearfix">
		<div class="main">

			<div id="review_list">
				<%=leavewordListHtml %>
			</div>
			
            <div id="review">
				<div class="title"><strong>您想对我说：</strong></div>
				<table>
					<tr>
						<td width="70"><label for="txtNickname">您的昵称：</label></td>
						<td><input id="txtNickname" class="textbox" type="text" value="" /><span><strong>*</strong>必填</span></td>
					</tr>
					<tr>
						<td><label for="txtEmail">邮箱地址：</label></td>
						<td><input id="txtEmail" class="textbox" type="text" value="" /><span><strong>*</strong>必填,但不会公开</span></td>
					</tr>
					<tr>
						<td><label for="txtWebsite">个人网站：</label></td>
						<td><input id="txtWebsite" class="textbox" type="text" value="" /></td>
					</tr>
                    <tr>
						<td><label for="txtLeaveCaption">留言标题：</label></td>
						<td><input id="txtLeaveCaption" style="width:500px;" class="textbox" type="text" value="" /></td>
					</tr>
					<tr>
						<td><label for="txtLeaveContent">留言内容：</label></td>
						<td><textarea id="txtLeaveContent" class="review_content"></textarea><span><strong>*</strong>必填(300汉字内)</span></td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td><input id="submitReview" class="submit" type="button" value="发表评论" /></td>
					</tr>
                    <tr>
						<td>&nbsp;</td>
						<td class="prompt"></td>
					</tr>
				</table>
			</div>
            <input id="LeaveIP" type="hidden" runat="server" />
		</div>
		<uc:Sidebar ID="Sidebar1" runat="server"/>
	</div>
</div>
<uc:Footer ID="Footer1" runat="server"/>
<script type="text/javascript">

    function GetByteLength(val) {
        var count = 0;
        for (var i = 0; i < val.length; i++) {
            if ((val.charCodeAt(i) < 0) || (val.charCodeAt(i) > 255))
                count = count + 2;
            else
                count = count + 1;
        }
        return count;
    }

    $(function () {

        $("#txtNickname,#txtEmail,#txtWebsite,#txtLeaveCaption,#txtLeaveContent").focusin(function () {
            $(this).css("background-color", "#FFF");
        });
        $("#txtNickname,#txtEmail,#txtWebsite,#txtLeaveCaption,#txtLeaveContent").focusout(function () {
            $(this).css("background-color", "#F0F0F0");
        });

        $("#submitReview").click(function () {

            if ($.trim($("#txtNickname").val()) == "") {
                $("#txtNickname").focus();
                $("#review .prompt").html("* 昵称不能为空 !")
                return false;
            }
            if ($.trim($("#txtEmail").val()) == "") {
                $("#txtEmail").focus();
                $("#review .prompt").html("* 邮箱不能为空 !")
                return false;
            }
            var reg = /^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
            if (!reg.test($("#txtEmail").val())) {
                $("#txtEmail").focus();
                $("#review .prompt").html("* 邮箱格式不正确 !")
                return false;
            }
            if ($.trim($("#txtLeaveCaption").val()) == "") {
                $("#txtLeaveCaption").focus();
                $("#review .prompt").html("* 留言标题不能为空 !")
                return false;
            }
            if ($.trim($("#txtLeaveContent").val()) == "") {
                $("#txtLeaveContent").focus();
                $("#review .prompt").html("* 留言不能为空 !")
                return false;
            }
            var textLength = GetByteLength($.trim($("#txtLeaveContent").val()));
            if (textLength < 10 || textLength > 600) {
                $("#txtLeaveContent").focus();
                $("#review .prompt").html("* 评论字节应大于10小于600 !")
                return false;
            }

            $(this).attr("disabled", "disabled");
            var LeaveName = $("#txtNickname").val();
            var LeaveEmail = $("#txtEmail").val();
            var LeaveUrl = $("#txtWebsite").val();
            var LeaveCaption = $("#txtLeaveCaption").val();
            var LeaveContent = $("#txtLeaveContent").val();
            var LeaveIP = $("#LeaveIP").val();

            var dataString = "LeaveName=" + LeaveName;
            dataString += "&LeaveEmail=" + LeaveEmail;
            dataString += "&LeaveUrl=" + LeaveUrl;
            dataString += "&LeaveCaption=" + LeaveCaption;
            dataString += "&LeaveContent=" + LeaveContent;
            dataString += "&LeaveIP=" + LeaveIP;

            $.ajax({ type: "post", url: "Ajax/AddLeaveword.ashx", data: dataString, success: function (result) {
                $("#submitReview").removeAttr("disabled");
                if (result == 1) {
                    $("#review .prompt").html("恭喜您,评论提交成功,留言需要审核后才能显示 !");
                    $("#txtNickname").val("");
                    $("#txtEmail").val("");
                    $("#txtWebsite").val("");
                    $("#txtLeaveCaption").val("");
                    $("#txtLeaveContent").val("");
                }
                else {
                    $("#review .prompt").html("很抱歉,留言提交失败 !");
                }
            }
            });
        });
    });
</script>
</form>
</body>
</html>
